<%@ page contentType="text/html;charset=utf-8" language="java"
	pageEncoding="UTF-8" import="java.util.Date"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<%@include file="../../common/mastertopedit.jsp"%>
<input type="hidden" id="emailParamId" value="${model.emailParamId}">
<input type="hidden" name="categoryId" id="categoryId"
		value="${model.categoryId}" /> 
<input type="hidden" name="cateLevel"
		id="cateLevel" value="${model.cateLevel}" />
<div class="form-horizontal pt-15  form-clean-magin">

	<div class="form-group">
		<label for="inputEmail3"
			class="col-xs-3 text-right control-label usual-label">邮件名称</label>
		<div class="col-xs-9">
			<input class="form-control form-control-260 pull-left" type="text"
				name="name" id="name" maxlength="100" type="text"
				value="${model.emailParam.name}"> <i class="plum-sign-right">*</i>
		</div>
	</div>

	<div class="form-group">
		<label for="inputEmail3"
			class="col-xs-3 text-right control-label usual-label">邮件主题</label>
		<div class="col-xs-9">
			<input class="form-control form-control-260 pull-left" type="text"
				name="subject" id="subject" maxlength="100" type="text"
				value="${model.emailParam.subject}">
				 <i class="plum-sign-right">*</i>
		</div>
	</div>
	<div class="form-group">
		<label for="inputEmail3"
			class="col-xs-3 text-right control-label usual-label">邮件内容</label>
		<div class="col-xs-9">
			<textarea id="content" rows="5"
				class="form-control form-control-260 pull-left">${model.emailParam.content}</textarea>
			<i class="plum-sign-right">*</i>
		</div>
	</div>

	<div class="form-group">
		<label for="inputEmail3"
			class="col-xs-3 text-right control-label usual-label">触发节点</label>
		<div class="col-xs-9">
			<select name="nodeId" id="nodeId"
				class="form-control form-control-260 pull-left">
				<option value=""
					<c:if test="${model.emailParam.nodeId==null}">selected="selected"</c:if>>请选择</option>
				<c:forEach items="${model.emailNodes}" var="lo"
					varStatus="itemStatus">
					<option value="${lo.id}"
						<c:if test="${model.emailParam.nodeId==lo.id}">selected="selected"</c:if>>${lo.name}</option>
				</c:forEach>
			</select> <i class="plum-sign-right">*</i>
		</div>
	</div>



	<div class="form-group">
		<label for="inputEmail3"
			class="col-xs-3 text-right control-label usual-label">商品类型</label>
		<div class="col-xs-9" id="treediv1">
			<input class="form-control form-control-260 pull-left" type="text" 
				name="cateName" id="cateName" maxlength="100" type="text" onclick="showCategory()" autocomplete="off"
				value="${model.cateName}"> <i
				class="plum-sign-right">*</i>
			<div id="treediv" class="treecategory" style="margin-left: 2px">

			</div>

		</div>
	</div>

	<div class="form-group">
		<label for="inputEmail3"
			class="col-xs-3 text-right control-label usual-label">接收人</label>
		<div class="col-xs-9">
			<input class="form-control form-control-260 pull-left" type="text"
				name="receiverUser" id="receiverUser" maxlength="100" type="text"
				value="${model.emailParam.receiverUser}"> <i
				class="plum-sign-right">*</i>
				<p class="line-tips">
				多个接收人，以英文下分号;隔开
			</p>
		</div>
	</div>
</div>

<div class="form-group text-center">
	<button type="button" class="runmi-btn runmi-primary"
		onclick="backIndex()">取消</button>
	<button type="button" class="runmi-btn runmi-sure-btn" onclick="save()">保存</button>
</div>
<script type="text/javascript">
	$(document).ready(function() {
		loadtree();
	});
	function loadtree() {
		postData = "1=1";
		var domainUrl = "${pageContext.request.contextPath}/item/category/cateview";
		$.ajax({
			type : "POST",
			url : domainUrl,
			data : postData,
			contentType : "application/x-www-form-urlencoded;charset=UTF-8",
			async : true, // 同步  true 异步。默认是异步
			error : function(resultdata) {
				//layer.closeAll();
			},
			success : function(resultdata) {
				$('#treediv').html(resultdata);
				$("#tree").treeview({
					collapsed : true
				});
				$("#treediv").hide();
			}
		});
	}
	
	function showCategory() {
		$("#treediv").show();
	}
	function selectcategory(cateLevel, categoryId, category3Name,
			category2Name, category1Name) {
		$('#cateId').val(categoryId);
		$('#catLevel').val(cateLevel);
		if (cateLevel == 1) {
			 $('#cateName').val(category1Name);
			 $('#categoryId').val(categoryId);
			 $('#cateLevel').val(cateLevel);
			 $("#treediv").hide();
		}
		if (cateLevel == 2) {
			 $('#cateName').val(category1Name + ">" + category2Name);
			 $('#categoryId').val(categoryId);
			 $('#cateLevel').val(cateLevel);
			 $("#treediv").hide();
		}
		if (cateLevel == 3) {
			$('#cateName').val(
					category1Name + ">" + category2Name + ">" + category3Name);
			$('#divCateName').html(
					category1Name + ">" + category2Name + ">" + category3Name);
			$("#treediv").hide();
			$('#categoryId').val(categoryId);
			$('#cateLevel').val(cateLevel);
		}
		
	}
	$("#treediv1").hover(function() {
		// $(".content").show();  
	}, function() {
		$("#treediv").hide();
	});

	function save() {
		var emailParamId = $('#emailParamId').val();
		var postData = "id=" + emailParamId;

		var name = $('#name').val();
		if (name == '') {
			layer.alert('请输入邮件名称');
			return;
		}
		postData = postData + "&name=" + encodeURIComponent(name);

		var subject = $('#subject').val();
		if (subject == '') {
			layer.alert('请输入邮件主题');
			return;
		}
		postData = postData + "&subject=" + encodeURIComponent(subject);

		var content = $('#content').val();
		if (content == '') {
			layer.alert('请输入邮件内容');
			return;
		}
		postData = postData + "&content=" + encodeURIComponent(content);

		
		var nodeId = $('#nodeId').val();
		if (nodeId == '') {
			layer.alert('请选择触发节点');
			return;
		}
		postData = postData + "&nodeId=" + encodeURIComponent(nodeId);
		
		var itemTypeId = $('#categoryId').val();
		postData = postData + "&itemTypeId=" + encodeURIComponent(itemTypeId);
		
		var receiverUser = $('#receiverUser').val();
		if (receiverUser == '') {
			layer.alert('请输入邮件接收人');
			return;
		}
		postData = postData + "&receiverUser=" + encodeURIComponent(receiverUser);
		
		
		
		layer.load(1, {
			shade : [ 0.5, '#fff' ]
		});
		//alert(postData);
		$.ajax({
			type : "POST",
			url : "saveEmailParam",
			data : postData,
			contentType : "application/x-www-form-urlencoded;charset=UTF-8",
			async : true, // 同步  true 异步。默认是异步
			dataType : 'json',
			error : function(resultdata) {
				layer.closeAll();
			},
			success : function(resultdata) {
				layer.closeAll();
				if (resultdata.returnCode == "0000") {
					layer.alert('操作成功', {
						icon : 1
					}, function() {
						parent.editReturn();
					});
				} else {
					layer.alert(resultdata.returnMessage);
				}
			}
		});
	}
	function backIndex() {
		parent.editReturn();
	}
</script>
<%@include file="../../common/masterbottom.jsp"%>
